package solution;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-18
 * Time: 15:20
 */
public class Solution3 {
    public static void main(String[] args) {
        String s = "abcde";
        LeftRotateString(s, 2);
        System.out.println(s);
    }
    public static void LeftRotateString(String str,int n){
        if (str == null || str.length() < n) {
            return;
        }
        int len = str.length();
        char[] ints = str.toCharArray();
        swap(ints, 0, len - 1);
        swap(ints, 0, n);
        swap(ints, n + 1, len - 1);
        str = String.copyValueOf(ints);
        System.out.println(str);
    }

    public static void swap(char[] arr, int left, int right) {
        while (left < right) {
            char temp = arr[right];
            arr[right] = arr[left];
            arr[left] = temp;
            left++;
            right--;
        }
    }
}
